﻿jsDebug = new function _jsDebug()
{
	this.errorBox = null;
	this.errorUL = null;
	this.history = new Object();
	this.historyObjects = new Object();
	this.maxErrors = 5;
	this.debugLevel = 255;	
	this.getErrorBox = _debugGetErrorBox;
	this.getErrorUL = _debugGetErrorUL;
	this.Throw = _debugThrow;
	
}

function _debugGetErrorBox()
{
	if(!this.errorBox)
	{
		this.errorBox = document.getElementById("jsDebugErrorBox");
		if(!this.errorBox)
		{
			this.errorBox = document.createElement("div");
			this.errorBox.setAttribute("id","jsDebugErrorBox");
			this.errorBox.setAttribute("class","CDebugErrorBox");
			this.errorBox.innerHTML = "Javascript Debugger";
			document.body.appendChild(this.errorBox);
		}
	}
	return this.errorBox;
	
}

function _debugGetErrorUL()
{
	if(!this.errorUL)
	{
		this.getErrorBox();
		this.errorUL = document.createElement("ul");
		this.errorBox.appendChild(this.errorUL);
	}
	return this.errorUL;
	
}

function _debugThrow(obj,level,txt)
{
	if(this.debugLevel<level)
		return;
	if(!this.history[obj])
	{
		this.history[obj] = new Array();
		var tmpObj = document.createElement("li");
		tmpObj.innerHTML = obj;
		this.getErrorUL().appendChild(tmpObj);
		this.historyObjects[obj] = document.createElement("ul");
		tmpObj.appendChild(this.historyObjects[obj]);
	}
	var exc = new jsException(this.history[obj].length,level,txt);
	this.history[obj].push(exc);
	var tmp = document.createElement("li");
	tmp.innerHTML = exc.id + "-" + exc.level + "- " + exc.txt;
	this.historyObjects[obj].appendChild(tmp);
	if(this.historyObjects[obj].childNodes.length>this.maxErrors)
	{
		this.historyObjects[obj].removeChild(this.historyObjects[obj].childNodes[0]);
	}
}




function jsException(id,level,txt)
{
	this.id = id;
	this.level = level;
	this.txt = txt;
}